//
//  ChangeViewController.m
//  豆瓣
//
//  Created by dllo on 15/11/4.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "ChangeViewController.h"
#import "MovieListViewController.h"
#import "MovieLatticeViewController.h"
#import "AppTools.h"
#import "Movie.h"

@interface ChangeViewController ()

@property (nonatomic, assign)BOOL isSelected;
@property (nonatomic, retain)MovieLatticeViewController *movieLattice;
@property (nonatomic, retain)MovieListViewController *movieList;


@end

@implementation ChangeViewController

- (void)dealloc
{
    [_movieLattice release];
    [_movieList release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [button setBackgroundImage:[UIImage imageNamed:@"btn_nav_list@2x.png"] forState:UIControlStateNormal];
    button.frame = CGRectMake(0, 0, 30, 40);
    button.backgroundColor = [UIColor whiteColor];
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];
    self.isSelected = NO;
    
    self.movieLattice = [[MovieLatticeViewController alloc] init];
    [self addChildViewController:self.movieLattice];
    [self.view addSubview:self.movieLattice.view];
    [self.movieLattice release];
    
    
    self.movieList = [[MovieListViewController alloc] init];
    [self addChildViewController:self.movieList];
    [self.view addSubview:self.movieList.view];
    [self.movieList release];
    
    
}

- (void)buttonAction:(UIButton *)btn
{
    if (self.isSelected == NO) {
        [UIView transitionFromView:self.movieList.view toView:self.movieLattice.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL finished) {
        }];
        
    }else{
        [UIView transitionFromView:self.movieLattice.view toView:self.movieList.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {
        }];
        
    }
    self.isSelected = !self.isSelected;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
